import {View} from "@tarojs/components";
import {useRef, useState} from "react";
import {Empty, Tab, Tabs} from "@antmjs/vantui";
import OrderList from "@/pages/tabbar/order/orderList";
import {OrderStatus, OrderStatusInfo} from "@/common/enums";
import {useDidShow, useTabItemTap} from "@tarojs/taro";
import LocalData from "@/common/local_data";
import Utils from "@/utils/common";
import LocalUtils from "@/utils/local_utils";



definePageConfig({
  navigationBarTitleText: '订单',
  enablePullDownRefresh: true,
  onReachBottomDistance: 50,
  enableShareAppMessage: true,
  enableShareTimeline: true,
})

export default function Order() {

  const tabs = useRef([
    {
      title: OrderStatusInfo[OrderStatus.ALL].text,
      key: OrderStatus.ALL // Key is the actual enum value (10)
    },
    {
      title: OrderStatusInfo[OrderStatus.WAIT_ACCEPT].text,
      key: OrderStatus.WAIT_ACCEPT // Key is the actual enum value (10)
    },
    {
      title: OrderStatusInfo[OrderStatus.PENDING].text,
      key: OrderStatus.PENDING // Key is the actual enum value (10)
    },
    {
      title: OrderStatusInfo[OrderStatus.WAIT_CONFIRMATION].text,
      key: OrderStatus.WAIT_CONFIRMATION // Key is the actual enum value (10)
    },
    {
      title: OrderStatusInfo[OrderStatus.WAIT_PAYMENT].text,
      key: OrderStatus.WAIT_PAYMENT // Key is the actual enum value (10)
    },
    {
      title: OrderStatusInfo[OrderStatus.FINISHED].text,
      key: OrderStatus.FINISHED // Key is the actual enum value (10)
    },
  ]);
  const [active, setActive] = useState(0)
  useDidShow(() => {
    setActive(LocalData.currentIndexOrder)
  })

  useTabItemTap((payload) => {
    Utils.goEditProfile()
  });
  return (
    <View className='container'>
      {
        LocalUtils.isLogin()?<Tabs
          active={active}
          swipeThreshold={6}
          sticky
          color='#56abe4'
        >
          {
            tabs.current.map((item, index) => (
              <Tab key={`tabs#demo1${index}`} title={item.title}>
                <View>
                  <OrderList item={item}></OrderList>
                </View>
              </Tab>
            ))
          }
        </Tabs>:<Empty description='未登录' />
      }
    </View>
  )
}


